package hu;

import java.util.*;

/**
 * 使用动态规划算法
 * dp[i][j]表示字符串A以i结尾的字串与字符串B以j结尾的字串是否匹配
 */
public class hu71 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine().toLowerCase();
        String p = sc.nextLine().toLowerCase();
        int m = p.length();
        int n = s.length();
        boolean[][] dp = new boolean[m + 1][n + 1];
        dp[0][0] = true;
        for (int i = 1; i <= m ; i++) {
            if(p.charAt(i - 1) == '*')
                dp[i][0] = true;
            else
                break;
        }
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                if(s.charAt(j - 1) == p.charAt(i - 1))
                    dp[i][j] = dp[i - 1][j - 1];
                if(p.charAt(i - 1) == '?' && ((s.charAt(j - 1) <= 'z' && s.charAt(i) >= 'a') || (s.charAt(i) <= '9' && s.charAt(i) >= '0'))){
                    dp[i][j] = dp[i - 1][j - 1];
                }
                if(p.charAt(i - 1) == '*' && ((s.charAt(j - 1) <= 'z' && s.charAt(i) >= 'a') || (s.charAt(i) <= '9' && s.charAt(i) >= '0'))){
                    dp[i][j] = dp[i - 1][j] | dp[i][j - 1] | dp[i - 1][j - 1];
                }
            }
        }
        System.out.println(dp[m][n]);
    }
}
/*
a*?*c
a@c
 */